import 'package:banyou_app/app/config/colors.dart';
import 'package:banyou_app/app/util/common_utils.dart';
import 'package:banyou_app/app/widget/app_bar_widget.dart';
import 'package:banyou_app/app/widget/load_network_image_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/userinfo_controller.dart';

class UserinfoView extends GetView<UserinfoController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(children: [
        Positioned.fill(
            child: Image.asset(
          'assets/images/背景@2x.png',
          width: 1.sw,
          height: 1.sh,
          fit: BoxFit.cover,
        )),
        Positioned.fill(
          child: SafeArea(
              child: SingleChildScrollView(
                  child: Container(
            padding: EdgeInsets.symmetric(horizontal: 16),
            child: Obx(() => controller.info.isEmpty
                ? Container()
                : Column(
                    children: [
                      SizedBox(height: 44 + ScreenUtil().statusBarHeight),
                      itemWidget(),
                      SizedBox(height: 10),
                      if (controller.islahei == 1) weilaheiWidget(),
                      if (controller.islahei == 2) laheiWidget()
                    ],
                  )),
          ))),
        ),
        Positioned(
          top: 0,
          right: 0,
          left: 0,
          height: 44 + ScreenUtil().statusBarHeight,
          child: SafeArea(
            child: AppBarWidget(
              titleStr: '个人详情',
              backgroundColor: Colors.transparent,
              actions: [
                InkWell(
                  onTap: () {
                    controller.clickCaozuo();
                  },
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 12),
                    child: Image.asset(
                      'assets/images/举报@2x.png',
                      width: 24,
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
      ]),
    );
  }

  Column weilaheiWidget() {
    return Column(
      children: [
        Container(
          decoration: BoxDecoration(
            color: ColorConfig.white,
            borderRadius: BorderRadius.all(Radius.circular(10.r)),
          ),
          padding: EdgeInsets.symmetric(horizontal: 12, vertical: 26),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              titleWidget('个性签名'),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
                child: Text(
                  controller.info['Signature'] ?? "",
                  style: TextStyle(
                    color: Color(0xFF959595),
                    fontSize: 14.sp,
                  ),
                ),
              ),
              SizedBox(height: 32),
              titleWidget('公开相册'),
              SizedBox(height: 5),
              imagesWidget(),
              SizedBox(height: 32),
              dongtaiWight(),
              SizedBox(height: 32),
              titleWidget1('期待陪伴'),
              SizedBox(height: 2),
              Container(
                child: Wrap(
                  children: controller.expectations
                      .map((item) => typeWidget(item))
                      .toList(),
                  spacing: 10,
                  runSpacing: 15,
                  alignment: WrapAlignment.start,
                  runAlignment: WrapAlignment.end,
                ),
              ),
              SizedBox(height: 26),
            ],
          ),
        ),
        const SizedBox(height: 20),
        InkWell(
          child: Container(
            width: 211.w,
            height: 45,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    Color(0xFFF52EC5),
                    Color(0xFFFF8A33),
                  ]),
              borderRadius: BorderRadius.circular(20),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Image.asset(
                  'assets/images/组 54@2x.png',
                  width: 18,
                ),
                SizedBox(
                  width: 5,
                ),
                Text(
                  "一起去旅游",
                  style: TextStyle(
                      color: ColorConfig.white,
                      fontSize: 16,
                      fontWeight: FontWeight.w500),
                ),
              ],
            ),
          ),
          onTap: () {
            controller.yiqi();
          },
        ),
        const SizedBox(height: 20),
      ],
    );
  }

  Widget dongtaiWight() {
    List dynamicsList = controller.info['Dynamics'] ?? [];
    return dynamicsList.isEmpty
        ? Container()
        : Column(
            children: [
              Row(
                children: [
                  titleWidget('最新动态'),
                  Spacer(),
                  InkWell(
                    onTap: () {
                      controller.allDongtai();
                    },
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 3),
                      child: Row(
                        children: [
                          Text('查看更多',
                              style: TextStyle(
                                  fontSize: 12.sp, color: Color(0xFF959595))),
                          Image.asset(
                            'assets/images/返回@2x.png',
                            width: 18,
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              Container(
                width: 1.sw,
                padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
                child: Text(
                  dynamicsList[0]['Content'] ?? "",
                  style: TextStyle(
                    color: ColorConfig.text_label,
                    fontSize: 14.sp,
                  ),
                ),
              ),
              SizedBox(height: 10),
              if ((dynamicsList[0]['PictureUrl'] ?? "").isNotEmpty)
                GridView.builder(
                    physics: const NeverScrollableScrollPhysics(),
                    shrinkWrap: true,
                    itemCount: 1,
                    gridDelegate:
                        const SliverGridDelegateWithFixedCrossAxisCount(
                            childAspectRatio: 1,
                            crossAxisCount: 3,
                            crossAxisSpacing: 10.0,
                            mainAxisSpacing: 10.0),
                    itemBuilder: (BuildContext context, int index) {
                      return InkWell(
                        onTap: () {
                          showImgs([dynamicsList[0]['PictureUrl']], 0);
                        },
                        child: Container(
                          clipBehavior: Clip.hardEdge,
                          decoration: BoxDecoration(
                            borderRadius:
                                BorderRadius.all(Radius.circular(10.r)),
                          ),
                          child: LoadNetworkImageWidget(
                              fit: BoxFit.cover,
                              height: double.infinity,
                              imageUrl: dynamicsList[0]['PictureUrl'] ?? ""),
                        ),
                      );
                    }),
            ],
          );
  }

  Widget typeWidget(item) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(15)),
          color: Color(0xFFEDEDED)),
      child: Text(item,
          style: TextStyle(color: ColorConfig.text_label, fontSize: 12.sp)),
    );
  }

  Widget imagesWidget() {
    return GridView.builder(
        physics: const NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        itemCount: (controller.info['Albums'] ?? []).length,
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            childAspectRatio: 1,
            crossAxisCount: 3,
            crossAxisSpacing: 10.0,
            mainAxisSpacing: 10.0),
        itemBuilder: (BuildContext context, int index) {
          return InkWell(
            onTap: () {
              showImgs(controller.info['Albums'], index);
            },
            child: Container(
              clipBehavior: Clip.hardEdge,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(10.r)),
              ),
              child: LoadNetworkImageWidget(
                  fit: BoxFit.cover,
                  height: double.infinity,
                  imageUrl: controller.info['Albums'][index]),
            ),
          );
        });
  }

  Widget titleWidget1(String titleStr) {
    return Container(
      child: Row(
        children: [
          Image.asset('assets/images/图像 19@2x.png', width: 40),
          SizedBox(width: 5),
          Text(
            titleStr,
            style: TextStyle(
                color: ColorConfig.text_label,
                fontSize: 16.sp,
                fontWeight: FontWeight.w600),
          ),
        ],
      ),
    );
  }

  Widget titleWidget(String titleStr) {
    return Container(
      child: Row(
        children: [
          Container(
            width: 4,
            height: 6,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    Color(0xFF755DF3),
                    Color(0xFFDF7EC0),
                  ]),
              borderRadius: BorderRadius.circular(2),
            ),
          ),
          SizedBox(width: 5),
          Text(
            titleStr,
            style: TextStyle(
                color: ColorConfig.text_label,
                fontSize: 16.sp,
                fontWeight: FontWeight.w600),
          ),
        ],
      ),
    );
  }

  Widget itemWidget() {
    return Container(
      width: 1.sw,
      clipBehavior: Clip.hardEdge,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(10.r)),
      ),
      child: AspectRatio(
        aspectRatio: 1,
        child: Stack(
          children: [
            Positioned.fill(
                child: LoadNetworkImageWidget(
                    width: 1.sw,
                    height: 1.sw,
                    fit: BoxFit.cover,
                    imageUrl: controller.info['UserAvatar'] ?? '')),
            Positioned.fill(
                child: Column(
              children: [
                Spacer(),
                Container(
                  width: 1.sw,
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Color(0x00000000).withAlpha(50),
                          Color(0xFF000000).withAlpha(50),
                        ]),
                  ),
                  padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text(controller.info['UserName'] ?? "",
                              style: TextStyle(
                                  fontSize: 18.sp, color: ColorConfig.white)),
                          SizedBox(width: 10),
                          controller.info['UserGender'] == '女'
                              ? Image.asset(
                                  'assets/images/女@2x.png',
                                  width: 18,
                                )
                              : Image.asset(
                                  'assets/images/nan.png',
                                  width: 20,
                                ),
                        ],
                      ),
                      Text(
                          '${controller.info['UserAge'] != null ? controller.info['UserAge'].toString() + "岁" : ""}/${controller.info['UserWeight'] ?? ""}',
                          style: TextStyle(
                              fontSize: 14.sp, color: ColorConfig.white)),
                      SizedBox(height: 10),
                    ],
                  ),
                )
              ],
            )),
            Positioned(
                right: 14,
                top: 14,
                child: InkWell(
                  onTap: () {
                    showImgs([controller.info['UserAvatar']], 0);
                    ;
                  },
                  child: Image.asset(
                    'assets/images/组 56@2x.png',
                    width: 26,
                    height: 26,
                  ),
                ))
          ],
        ),
      ),
    );
  }

  laheiWidget() {
    return Center(
      child: Column(
        children: [
          const SizedBox(height: 20),
          Image.asset('assets/images/组 447@2x.png', width: .4.sw),
          const SizedBox(height: 40),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
            child: Text(
              "你已经拉黑对方，无法查看TA的内容",
              style: TextStyle(
                color: Color(0xFF959595),
                fontSize: 14.sp,
              ),
            ),
          ),
          const SizedBox(height: 20),
          InkWell(
            child: Container(
              width: 211.w,
              height: 45,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                    colors: [
                      Color(0xFFF52EC5),
                      Color(0xFFFF8A33),
                    ]),
                borderRadius: BorderRadius.circular(20),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    "解除拉黑",
                    style: TextStyle(
                        color: ColorConfig.white,
                        fontSize: 16,
                        fontWeight: FontWeight.w500),
                  ),
                ],
              ),
            ),
            onTap: () {
              controller.jiechu();
            },
          ),
          const SizedBox(height: 20),
        ],
      ),
    );
  }
}
